<template>
	<view class="orderRecordVisitor-appcontainer">
		<view class="dateTimePicker">
			<uni-datetime-picker class="uni-datetime-picker"
				type="daterange"
				v-model="range"
				returnType="string"
				:clear-icon="true"
				:border="true"
				:start="new Date().toDateString()"
				rangeSeparator="至"
				@change="pickerDateRange"
			></uni-datetime-picker>
		</view>
		<scroll-view
			scroll-y="true" 
			class="scroll-Y"
			:style="{height:cssheight}"
			lower-threshold="50"
			@scrolltolower="scrollToLower">
			<view class="orderItem" v-for="(item,index) in list" :key="item.visitorSignkey">
				<view class="title">
					<view class="titleLeft">
						<text class="iconfont icon-manglu"></text>
						访客：{{item.visitorName}}
					</view>
					<view class="titleRight">
						<view class="deleteButton" @click="cancelVisitor(item.visitorSignkey)">
							<text class="iconfont icon-icon-test44"></text>
							取消预约
						</view>
					</view>
				</view>
				<view class="info">
					<view class="phone">
						<text class="iconfont icon-icon-test24"></text>
						联系电话：{{item.visitorPhone}}
					</view>
					<view class="appointment">
						<text class="iconfont icon-icon-test22"></text>
						预约时间：{{item.appointment}}
					</view>
					<view class="time">
						<text class="iconfont icon-icon-test5"></text>
						来访时间：{{item.visiting == null ? '未造访' : item.visiting}}
					</view>
				</view>
				<view class="QRcode" @click="goDeatilVisitor(item.visitorSignkey)">
					访客二维码
				</view>
			</view>
			<view class="noData" v-if="noDataShow">
				-- 已经没有数据了 --
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				visitorVo: {
					beginDate: null,
					endDate:null
				},				
				current: 1,
				limit: 8,
				list: [],
				total: 0,
				pages: 0,
				range: [],
				cssheight:'',
				userInfo:{},
				noDataShow: false
			};
		},
		onLoad() {
			this.getUserInfo()
		},
		onReady() {
			var _this = this
			var css = ''
			uni.getSystemInfo({
				success: (resu) => {
					const query = uni.createSelectorQuery()
					query.select('.scroll-Y').boundingClientRect()
					query.exec(function(res){
						_this.height = resu.windowHeight -res[0].top + 'px'
						// console.log(_this.height)
						css = _this.height
					})
				}
			})
			this.cssheight = css
		},
		methods:{
			//选择对应的日期
			pickerDateRange(e){
				// console.log(e)
				this.visitorVo.beginDate = e[0]
				this.visitorVo.endDate = e[1]
				this.list = []
				this.getPageList()
			},
			//获得访客列表
			getPageList(page = 1){
				this.current = page
				this.$myReq({
					url: `/owner/visitor/futureVisitorPageList/${this.userInfo.signKey}/${this.current}/${this.limit}`,
					method: 'post',
					data: this.visitorVo
				})
				.then((res) => {
					// console.log(res)
					this.list = [...this.list,...res.data.records]
					this.total = res.data.total
					this.pages = res.data.pages
					this.current = res.data.current
					if(res.data.records.length < 8){
						this.noDataShow = true
					}
				})
				.catch((err) => {
					console.log(err)
				})
			},
			//加载下一页数据
			scrollToLower(){
				this.getPageList(this.current += 1)
			},
			//取消预约
			cancelVisitor(visitorSignkey){
				this.$myReq({
					url:`/owner/visitor/visitor/${visitorSignkey}`,
					method:'delete'
				})
				.then((res) => {
					uni.showToast({
						title:'已取消预约',
						image:'../../../static/Icon/facility/orderSuccess.png',
						position:'top',
						duration:2000
					})
					this.list = []
					this.getPageList()
				})
			},
			//去新增访客页面
			goAddVisitor(){
				uni.navigateTo({
					url:'../addVisitor/addVisitor'
				})
			},
			//去访客详情页面
			goDeatilVisitor(visitorSignkey){
				uni.navigateTo({
					url:'../qrCodeVisitor/qrCodeVisitor?visitorSignkey='+visitorSignkey,
					fail: (err) => {
						console.log(err)
					}
				})
			},
			//获得用户信息
			getUserInfo(){
				const token = uni.getStorageSync("userToken")
				// console.log(token)
				this.$myReq({
					url: '/owner/login/loginUserInfo/' + token,
					method:'GET'
				})
				.then((res) => {
					// console.log(res)
					this.userInfo = res.data
					this.getPageList()
				})
			}
		}
}
</script>

<style lang="scss">
.orderRecordVisitor-appcontainer{
}
.dateTimePicker{
	padding: 40rpx 30rpx 30rpx 30rpx;
	border-bottom: 4rpx solid $main-colorB;
}
scroll-view{
	padding: 30rpx 30rpx 0rpx 30rpx;
	background-color: #f6f6f6;
	.orderItem{
		margin-bottom: 30rpx;
		background-color: #FFFFFF;
		box-shadow: 0rpx 0rpx 4rpx 4rpx #d0d0d0;
		border-radius: 20rpx;
		overflow: hidden;
		width: 690rpx;
		.title{
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			border-bottom: 1px solid #f6f6f6;		
			padding: 30rpx 30rpx 10rpx 30rpx;
			.titleLeft{
				text{
					margin-right: 10rpx;
				}
				font-size: 40rpx;
				height: 80rpx;
				line-height: 80rpx;
			}
			.titleRight{
				width: 170rpx;
				display: flex;
				align-items: center;
				.deleteButton{
					height: 60rpx;
					width: 100%;
					color: #FFFFFF;
					font-size: 25rpx;
					line-height: 60rpx;
					border-radius: 10rpx;					
					text-align: center;
					background-color: $main-colorB;
					text{
						font-size: 25rpx;
						line-height: 60rpx;
						margin-right: 10rpx;
					}
				}
			}
		}
		.info{
			padding: 20rpx 30rpx 10rpx 30rpx;
			view{
				margin-bottom: 10rpx;
				font-size: 30rpx;
				color: $main-garyB;
			}
		}
		.QRcode{
			padding: 10rpx 30rpx 10rpx 30rpx;
			color: $main-colorA;
			height: 60rpx;
			text-align: center;
			line-height: 60rpx;
			background-color: #fafafa;
			border-top: 2rpx solid #e8e8e9;
		}
	}
	.noData{
		// border: 1px solid red;
		text-align: center;
		line-height: 150rpx;
		color: $main-garyB;
		height: 150rpx;
		width: 690rpx;
	}
}

</style>
